<?php
declare(strict_types=1);
namespace App\Controller\Api\V1\Ad;

use App\Controller\Api\BaseController;
use App\Model\CmsPost;
use App\Repositories\AdDatumRepository;

class DataController extends BaseController
{
    public function list(){
        $rows = $this->request->input('rows',10);
        $space_id = (int)$this->request->input('space_id',0);
        if(!$space_id){
            return $this->response->error(10015,'请传入广告位');
        }
        $search['space_id'] = [
            'field'=>'space_id',
            'value'=>$space_id,
        ];
        $search['status'] = [
            'field'=>'status',
            'value'=>1
        ];
        $orderBy=[[
            'field' => 'id',
            'sort' => 'desc'
        ]];
        $datas = AdDatumRepository::getInstance()->all('*',$search,$orderBy);
        $return=[];
        if($rows==1){
            $return=$datas->count()?$datas[0]:new \stdClass();
        }else{
            $return = $datas;
        }
        return $this->response->success($return);
    }
}